package net.starwifi.duobao.hfg.query;

import cn.com.hongpay.client.utils.SignatureTools;
import com.alibaba.fastjson.JSONObject;
import net.starwifi.duobao.hfg.APIResponse;

/**
 * Created by STX on 2016/4/11.
 */
public class QueryResponse extends APIResponse {

    private String partner_trade_no;

    private String ret_code;

    private String ret_msg;

    private String partner_id;

    private String signed_msg;

    public QueryResponse() {
    }

    public QueryResponse(String partner_trade_no, String request_time, String ret_code, String ret_msg, String partner_id, String signed_msg) {
        this.partner_trade_no = partner_trade_no;
        this.ret_code = ret_code;
        this.ret_msg = ret_msg;
        this.partner_id = partner_id;
        this.signed_msg = signed_msg;
    }

    @Override
    public void parseRes(String json) {
        JSONObject jsonObject= JSONObject.parseObject(json);
        JSONObject body=JSONObject.parseObject(jsonObject.get("body").toString());
        JSONObject head=JSONObject.parseObject(jsonObject.get("head").toString());

        partner_trade_no=body.get("partner_trade_no").toString();
        ret_code=body.get("ret_code").toString();
        ret_msg=body.get("ret_msg").toString();
        partner_id=head.get("partner_id").toString();
        signed_msg=head.get("signed_msg").toString();



//        signed_msg=makeSign(pfxFile,pfxPwd,privateKeyPwd);
//        StringBuffer body=new StringBuffer();
//        body.append("partner_trade_no:"+partner_trade_no);
//        body.append(",request_time:"+request_time);
//        body.append(",ret_code:"+ret_code);
//        body.append(",ret_msg:"+ret_msg);
//
//        StringBuffer head=new StringBuffer();
//        head.append("partner_id:"+partner_id);
//        head.append(",signed_msg:"+signed_msg);
//
//        String json="{body:{"+body.toString()+"},head{"+head.toString()+"}}";
//        return json;
    }

    @Override
    public String makeSign(String pfxFile, String pfxPwd, String privateKeyPwd) {

        StringBuffer sb=new StringBuffer();
        sb.append("partner_id:"+partner_id);
        sb.append(";partner_trade_no:"+partner_trade_no);
//        sb.append(";request_time:"+request_time);

        SignatureTools st = new SignatureTools();
        String sign= st.sign(sb.toString(),pfxFile, pfxPwd, privateKeyPwd);
        return sign;
    }

    public String getPartner_trade_no() {
        return partner_trade_no;
    }

    public void setPartner_trade_no(String partner_trade_no) {
        this.partner_trade_no = partner_trade_no;
    }

    public String getRet_code() {
        return ret_code;
    }

    public void setRet_code(String ret_code) {
        this.ret_code = ret_code;
    }

    public String getRet_msg() {
        return ret_msg;
    }

    public void setRet_msg(String ret_msg) {
        this.ret_msg = ret_msg;
    }

    public String getPartner_id() {
        return partner_id;
    }

    public void setPartner_id(String partner_id) {
        this.partner_id = partner_id;
    }

    public String getSigned_msg() {
        return signed_msg;
    }

    public void setSigned_msg(String signed_msg) {
        this.signed_msg = signed_msg;
    }


}
